package com.lz.football.module.ladderMatch.exchange
{
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.shop.ShopDataManager;
	
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.managers.TipsManager;
	
	public class ExchangeBaseItem extends Sprite implements IExchangeItem
	{
		public var symbolSkin		:MovieClip;//皮肤
		/**
		 *选中框  
		 */
		public var _frame:MovieClip;
		/**
		 *物品容器 
		 */
		public var _picture:MovieClip;
		/**
		 *物品图片 
		 */
		public var _image:Bitmap;
		/**
		 *物品名称  
		 */
		public var _goodName:TextField;
		/**
		 *荣誉值 
		 */
		public var _value:TextField;
		public var _height:int;
		public var _width:int;
		/**
		 *选中状态 
		 */
		public var _selectStatus:Boolean;
		/**
		 * 
		 */
		public var _vo:GoodsVo;
		/**
		 * 
		 */
		public var _callBack:Function;
		/**
		 *背景 
		 */
		public var _changeBg:MovieClip;
		public function ExchangeBaseItem()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			_frame = symbolSkin._frame;
			_picture = symbolSkin._picture;
			_goodName = symbolSkin._goodName;
			_value = symbolSkin._value;
			_changeBg = symbolSkin.changeBg;
			
			if(_frame.parent)_frame.parent.removeChild(_frame);
			_height = symbolSkin.height;
			_width = symbolSkin.width;
			_changeBg.gotoAndStop(1);
			_changeBg.visible = false;
		}
		/**
		 *显示数据 
		 * @param $vo
		 * 
		 */
		public function setDate($vo:GoodsVo):void
		{
			_vo =  $vo;
			if(_image == null)_image= new Bitmap();
			_image.bitmapData = $vo.bitmapData
			_picture.addChild(_image);
			_goodName.text = $vo.name;
			addEvtListener();
		}
		
//		public function setData($vo:GoodVo):void
//		{
//			
//			
//		}
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.CLICK,onClickHandler);
			this.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
		}
		protected function onOutHandler(event:MouseEvent):void
		{
			TipsManager.hide();
			if(_selectStatus)return;
			if(_frame.parent)_frame.parent.removeChild(_frame);
		}
		
		protected function onOverHandler(event:MouseEvent):void
		{
			//			TipsManager.show(TipsConst.GOODSTEXTTIPS,tipString());
//			if(ShopDataManager.PALYERGOOD == _vo.type)
//			{
//				TipsManager.show(TipsConst.PLAYERITEMTIPS,_vo);
//			}else if(ShopDataManager.OTHERGOOD == _vo.type)
//			{
//				TipsManager.show(TipsConst.EQUIPTIPS,_vo);
//			}else
//			{
//				TipsManager.show(TipsConst.GOODSTEXTTIPS,tipString());
//			}
			if(_selectStatus)return;
			this.addChild(_frame);
		}
		private function tipString():Object
		{
			return null;
		}
		public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.CLICK,onClickHandler);
			this.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			this.removeEventListener(MouseEvent.ROLL_OVER,onOverHandler);
		}
		
		public function destroyView():void
		{
		}
		override public function get height():Number
		{
			return _height;
		}
		override public function get width():Number
		{
			return _width;
		}
		public function get goodVo():GoodsVo
		{
			return _vo;
		}
		
		public function set callBack($value:Function):void
		{
			_callBack = $value;
		}
		/**
		 * 重置
		 * 
		 */
		public function reSet():void
		{
			removeEvtListener();
			select = false;
//			_honourIcon.visible = false;
			_goodName.text = "";
			_value.text = "";
			if(_image != null && _image.parent)_picture.removeChild(_image);
		}
		/**
		 *设置选中 
		 * @param $value
		 * 
		 */
		public function set select($value:Boolean):void
		{
			_selectStatus= $value;
			if($value)
			{
				this.addChild(_frame);
			}else
			{
				if(_frame.parent)_frame.parent.removeChild(_frame);
			}
		}
		protected function onClickHandler(event:MouseEvent):void
		{
			if(_selectStatus)return;
			if(_callBack != null)_callBack(this);
		}
		public function setcontribution($value:int):void
		{
			
		}
	}
}